'''
Created on 2010-10-11

@author: tongji@rekoo.com
'''
import os
import sys
import datetime
from collections import defaultdict

if __name__ == '__main__':
    today = datetime.date.today()
    oneweeksago = today - datetime.timedelta(days=7)
    twoweeksago = today - datetime.timedelta(days=14)
    threeweeksago = today - datetime.timedelta(days=21)
    data = defaultdict(lambda : [0,0,0,0])
    
    for line in sys.stdin:
        try:
            uid, login_time, add_time, platform, ds = line.strip().split('\t')
            login_time = login_time.split()[0]
            add_time = add_time.split()[0]
            ds = ds.split()[0]
            login_time, add_time, ds = map(lambda x : datetime.datetime.strptime(x, '%Y-%m-%d').date(), [login_time, add_time, ds])
            print login_time, add_time, ds
            if add_time >= oneweeksago:
                data[uid][3] = 1
            if threeweeksago <= login_time < twoweeksago:
                data[uid][0] = 1
            elif twoweeksago <= login_time < oneweeksago:
                data[uid][1] = 1
            elif oneweeksago <= login_time < today:
                data[uid][2] = 1
        except Exception, e:
            print e
    
    for key, value in data.items():
        value_string = ','.join(map(str, value))
        record = '\t'.join([key, value_string])
        print record
    
        
        
        
        
